package com.empire.module.sporttery.service.footballmatchodd;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.empire.module.sporttery.controller.admin.footballmatchodd.vo.*;
import com.empire.module.sporttery.dal.dataobject.footballmatchodd.FootballMatchOddDO;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.util.object.BeanUtils;

import com.empire.module.sporttery.dal.mysql.footballmatchodd.FootballMatchOddMapper;

import static com.empire.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.empire.module.sporttery.enums.ErrorCodeConstants.*;

/**
 * 竞猜足球指数 Service 实现类
 *
 * @author 无敌仙人
 */
@Service
@Validated
public class FootballMatchOddServiceImpl implements FootballMatchOddService {

    @Resource
    private FootballMatchOddMapper footballMatchOddMapper;

    @Override
    public Integer createFootballMatchOdd(FootballMatchOddSaveReqVO createReqVO) {
        // 插入
        FootballMatchOddDO footballMatchOdd = BeanUtils.toBean(createReqVO, FootballMatchOddDO.class);
        footballMatchOddMapper.insert(footballMatchOdd);
        // 返回
        return footballMatchOdd.getId();
    }

    @Override
    public void updateFootballMatchOdd(FootballMatchOddSaveReqVO updateReqVO) {
        // 校验存在
        validateFootballMatchOddExists(updateReqVO.getId());
        // 更新
        FootballMatchOddDO updateObj = BeanUtils.toBean(updateReqVO, FootballMatchOddDO.class);
        footballMatchOddMapper.updateById(updateObj);
    }

    @Override
    public void deleteFootballMatchOdd(Integer id) {
        // 校验存在
        validateFootballMatchOddExists(id);
        // 删除
        footballMatchOddMapper.deleteById(id);
    }

    private void validateFootballMatchOddExists(Integer id) {
        if (footballMatchOddMapper.selectById(id) == null) {
            throw exception(FOOTBALL_MATCH_ODD_NOT_EXISTS);
        }
    }

    @Override
    public FootballMatchOddDO getFootballMatchOdd(Integer id) {
        return footballMatchOddMapper.selectById(id);
    }

    @Override
    public PageResult<FootballMatchOddDO> getFootballMatchOddPage(FootballMatchOddPageReqVO pageReqVO) {
        return footballMatchOddMapper.selectPage(pageReqVO);
    }

}